package com.prs.crm.dao.purchase.impl;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.purchase.SupplierInquiryDao;
import com.prs.crm.domain.purchase.SupplierInquiry;

public class SupplierInquiryDaoImp extends BaseDaoImpl<SupplierInquiry> implements SupplierInquiryDao {

	@SuppressWarnings("unchecked")
	@Override
	public Collection<SupplierInquiry> findByIds(final Integer[] ids) {
		// TODO Auto-generated method stub
		return (Collection<SupplierInquiry>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(SupplierInquiry.class);
				criteria.add(Restrictions.in("id", ids));
				return criteria.list();
			}
		});
	}

	@Override
	public SupplierInquiry getSupplierInquiry(Serializable id) {
	
		return this.getHibernateTemplate().get(SupplierInquiry.class, id);
	}

	@Override
	public void saveOrUapedate(SupplierInquiry supplierInquiry) {
		this.getHibernateTemplate().saveOrUpdate(supplierInquiry);
	}

}
